package cn.im.qywx.wx.util;

import cn.im.qywx.view.WeiXinXml;
import org.thymeleaf.util.StringUtils;

import java.util.Date;


/**
 * @Description: 解析微信消息
 */
public class WriteWeiXinMsgXml implements WriteXml {

	/**
	 * 拼装数据返回给用户
	 */
	public void writeXml(WeiXinXml wXml) {

		if (null == wXml) {
			return;
		}

		if (null != wXml 
				&& !StringUtils.isEmpty(wXml.getToUserName())
				&& !StringUtils.isEmpty(wXml.getFromUserName())
				&& !StringUtils.isEmpty(wXml.getContent())) {

			String reResponse = "<xml>";
			reResponse += "<ToUserName>" + wXml.getFromUserName() + "</ToUserName>";
			reResponse += "<FromUserName>" + wXml.getToUserName() + "</FromUserName>";
			reResponse += "<CreateTime>" + new Date().getTime() + "</CreateTime>";
			reResponse += "<MsgType><![CDATA[text]]></MsgType>";
			reResponse += "<Content><![CDATA[" + wXml.getContent() + "]]></Content>";
			reResponse += "</xml>";
			
			wXml.setServerSendXml(reResponse);
		}

	}

}
